﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;

namespace DPMQWindowsService
{
    public class LogWriter
    {

        private volatile static log4net.ILog log = null;
        private static LogWriter _instance = null;
        private static readonly object lockHelper = new object();

        public static LogWriter Instance
        {
            get
            {
                lock (lockHelper)
                {
                    if (_instance == null)
                    {
                        _instance = new LogWriter();
                        if (log == null)
                            log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

                    }

                }
                return _instance;
            }
        }



        public void writeError(Object errorMsg, Exception exe)
        {
            try
            {
                if (errorMsg != null)
                    log.Error(errorMsg.ToString(), exe);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message);
            }
        }
        public void writeError(Object errorMsg)
        {
            try
            {
                if (errorMsg != null)
                    log.Error(errorMsg.ToString());
            }
            catch (Exception ex)
            {
                log.Info(ex.Message);
            }
        }
        public void writeInfo(Object infoMsg, Exception exe)
        {
            try
            {
                if (infoMsg != null)
                    log.Info(infoMsg.ToString(), exe);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message);
            }
        }
        public void writeInfo(Object infoMsg)
        {
            try
            {
                if (infoMsg != null)
                    log.Info(infoMsg.ToString());
            }
            catch (Exception ex)
            {
                log.Info(ex.Message);
            }
        }


    }


}
